package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.WeekService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class WeekController {
    @Autowired
    WeekService weekService;
    @RequestMapping("/findCount")
    public Object findCount(){
        List<Map> list = weekService.findCount();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray mapArray = new JSONArray();
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("name",map.get("name"));
            mapObject.put("value",map.get("count"));

            mapArray.add(mapObject);
        }
        dataObject.put("mapData",mapArray);
        dataObject.put("valueName","下单次数");
        jsonObject.put("data",dataObject);
        return jsonObject;
    }
    @RequestMapping("/findTotal")
    public Object findTotal(){
        List<Map> list = weekService.findTotal();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            JSONObject dataObject = new JSONObject();
            dataObject.put("name",map.get("type"));
            dataObject.put("value",map.get("total"));

            dataArray.add(dataObject);
        }
        jsonObject.put("data",dataArray);
        return jsonObject;
    }

    @RequestMapping("/findSum")
    public Object findSum(String money){
        List<Map> list = weekService.findSum(money);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("sum(amount)"));
        return jsonObject;
    }
    @RequestMapping("/findJu")
    public Object findJu(){
        return weekService.findJu();
    }
    @RequestMapping("/findMax")
    public Object findMax(){
        return weekService.findMax();
    }
}
